package org.dingfugui.triple.link.zk;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 远程服务
 *
 * @author fugui.ding at 2015/7/27
 */
public class RemoteServer {
    private String appName;
    private String url;

    Queue<ZookeeperConnection> queue = new LinkedBlockingQueue<>();


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getPort() {
        String[] urlArray = url.split(":");
        int port = Integer.parseInt(urlArray[1]);
        return port;
    }

    public String getIp() {
        String[] urlArray = url.split(":");
        String ip = urlArray[0];
        return ip;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getAppName() {
        return appName;
    }

    public Queue<ZookeeperConnection> getQueue() {
        return queue;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RemoteServer that = (RemoteServer) o;

        if (appName != null ? !appName.equals(that.appName) : that.appName != null) return false;
        return !(url != null ? !url.equals(that.url) : that.url != null);
    }

    @Override
    public int hashCode() {
        int result = appName != null ? appName.hashCode() : 0;
        result = 31 * result + (url != null ? url.hashCode() : 0);
        return result;
    }
}
